package com.tsunami.authority.enums.auth;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @Classname GrantType
 * @Description TODO
 * @Date 2021-12-01 16:16
 * @Created by lx
 */
@Getter
@NoArgsConstructor
@ApiModel(value = "GrantType", description = "授权类型-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum GrantType {
    AUTHORIZATION_CODE("authorization_code","授权码模式"),
    PASSWORD("password", "密码模式"),
    CLIENT_CREDENTIALS("client_credentials", "客户端模式"),
    IMPLICIT("implicit", "简化模式"),
    REFRESH_TOKEN("refresh_token", "刷新");
    private String code;
    private String info;

    GrantType(String code, String info)
    {
        this.code = code;
        this.info = info;
    }
    public String getCode()
    {
        return code;
    }

    public String getInfo()
    {
        return info;
    }

    public static GrantType getEnum(String code) {
        for (final GrantType item : GrantType.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }
}
